package org.behrang.macbeans.tab.bm;

import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Insets;
import javax.swing.border.Border;
import org.behrang.macbeans.Utils;

/**
 *
 * @author Behrang Saeedzadeh <behrangsa@gmail.com>
 */
public class BMUpperTabControlBorder implements Border {

    public static final Color L12 = new Color(206, 206, 206);
    public static final Color L13 = new Color(182, 182, 182);
    public static final Color L14 = new Color(183, 183, 183);
    public static final Color L1 = new Color(191, 191, 191);
    
    public static final Color L21 = new Color(205, 205, 205);
    public static final Color L22 = new Color(171, 171, 171);
    public static final Color L23 = new Color(193, 193, 193);
    public static final Color L24 = new Color(210, 210, 210);
    public static final Color L2 = new Color(219, 219, 219);
    
    public static final Color L31 = new Color(177, 177, 177);
    public static final Color L32 = new Color(184, 184, 184);
    public static final Color L33 = new Color(209, 209, 209);
    
    public static final Color BG = new Color(224, 224, 224);
    
    public static final Color U1 = new Color(168, 168, 168);
    public static final Color U2 = new Color(191, 191, 191);
    public static final Color U3 = new Color(213, 213, 213);
    public static final Color U4 = new Color(223, 223, 223);
    
    public Insets getBorderInsets(Component c) {
        return new Insets(BMViewTabDisplayerUI.TOP_PADDING, 
                BMViewTabDisplayerUI.LEFT_PADDING,
                BMViewTabDisplayerUI.BOTTOM_PADDING, 
                BMViewTabDisplayerUI.RIGHT_PADDING);
    }

    public boolean isBorderOpaque() {
        return true;
    }

    public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
        
        g.setColor(BG);
        g.fillRect(x + 1, y + 1, width - 2, height - 2);
        
        // left
        drawPixel(g, L12, x, y + 1);
        drawPixel(g, L13, x, y + 2);
        drawPixel(g, L14, x, y + 3);
        
        g.setColor(L1);
        g.drawLine(x, y + 4, x, y + 4 + height);
        
        drawPixel(g, L21, x + 1, y);
        drawPixel(g, L22, x + 1, y + 1);
        drawPixel(g, L23, x + 1, y + 2);
        drawPixel(g, L24, x + 1, y + 3);
        
        g.setColor(L2);
        g.drawLine(x + 1, y + 4, x + 1, y + 4 + height);
        
        drawPixel(g, L31, x + 2, y);
        drawPixel(g, L32, x + 2, y + 1);
        drawPixel(g, L33, x + 2, y + 2);
        
        // right
        int _x = x;
        x = _x + width - 1;
        drawPixel(g, L12, x, y + 1);
        drawPixel(g, L13, x, y + 2);
        drawPixel(g, L14, x, y + 3);
        
        g.setColor(L1);
        g.drawLine(x, y + 4, x, y + 4 + height);
        
        x = _x + width - 3;
        drawPixel(g, L21, x + 1, y);
        drawPixel(g, L22, x + 1, y + 1);
        drawPixel(g, L23, x + 1, y + 2);
        drawPixel(g, L24, x + 1, y + 3);
        
        g.setColor(L2);
        g.drawLine(x + 1, y + 4, x + 1, y + 4 + height);
        
        x = _x + width - 5;
        drawPixel(g, L31, x + 2, y);
        drawPixel(g, L32, x + 2, y + 1);
        drawPixel(g, L33, x + 2, y + 2);
        
        x = _x;
        // up
        g.setColor(U1);
        g.drawLine(x + 3, y, x + width - 3, y);
        g.setColor(U2);
        g.drawLine(x + 3, y + 1, x + width - 3, y + 1);
        g.setColor(U3);
        g.drawLine(x + 3, y + 2, x + width - 3, y + 2);
        g.setColor(U4);
        g.drawLine(x + 3, y + 3, x + width - 3, y + 3);
        
    }
    
    private void drawPixel(Graphics g, Color c, int x, int y) {
        g.setColor(c);
        g.drawLine(x, y, x, y);
    }
    
}
